package com.qf.controller;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.GoodsType;
import com.qf.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Autowired
    GoodsTypeService goodsTypeService;

    @RequestMapping("/goodstypelist")
    public void goodstypelist(HttpServletResponse resp) throws IOException {
        //查询一级商品分类
        List<GoodsType> goodsType1 = goodsTypeService.getGoodsType1();

        //把数据列表转换为json
        String res = JSON.toJSONString(goodsType1);
        System.out.println(res);
        //响应前端
        resp.setCharacterEncoding("utf-8");
        resp.getWriter().write(res);
    }
}
